package aiku.numericalcontroloa.Service.productType;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import aiku.numericalcontroloa.Base.Utils.Result;
import aiku.numericalcontroloa.Mapper.productType.productTypeMapper;
import aiku.numericalcontroloa.Model.Entity.productType.productType;

@Service
public class productTypeServiceImp implements productTypeService {

    @Autowired
    private productTypeMapper productTypeMapper;

    @Override
    public Result getProductType() {
        List<productType> list = productTypeMapper.selectList(null);
        return Result.success("查询完成", list);
    }

    @Override
    public Result addProductType(productType data) {
        if (data == null && data.getProductType() == null && data.getRelevance() == null && data.getProductType() == ""
                && data.getRelevance() == "") {
            return Result.error("参数为空");
        }
        data.setDeleted(0);
        data.setId(null);
        if (productTypeMapper.insert(data) == 1) {
            return Result.success("添加成功");
        } else {
            return Result.error("添加失败");
        }
    }

    @Override
    public Result updateProductType(productType data) {
        if (data == null && data.getProductType() == null && data.getProductType() == "") {
            return Result.error("参数为空");
        }
        if (productTypeMapper.updateById(data) == 1) {
            return Result.success("修改成功");
        } else {
            return Result.error("修改失败");
        }
    }

    @Override
    public Result deleteProductType(productType data) {
        if (data == null) {
            return Result.error("参数为空");
        }
        data.setDeleted(1);
        if (productTypeMapper.deleteById(data) == 1) {
            return Result.success("删除成功");
        } else {
            return Result.error("删除失败");
        }
    }

}
